package com.sunday.volunteer.admin;

import android.app.Application;
import android.text.TextUtils;

import com.google.gson.Gson;
import com.sunday.common.logger.Logger;
import com.sunday.member.utils.SharePerferenceUtils;
import com.sunday.volunteer.admin.entity.Member;

/**
 * Created by Administrator on 2016/10/8.
 */
public class BaseApp extends Application implements Thread.UncaughtExceptionHandler {


    private static BaseApp instance;

    private static int villageId = -1;
    private String tempcoor = "bd09ll";
    public static boolean clearCrat = false;

    public synchronized static BaseApp getInstance() {
        return instance;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        instance = this;
        Logger.init("Sunday").hideThreadInfo().setMethodCount(3).setMethodOffset(2);
        Thread.setDefaultUncaughtExceptionHandler(this);
    }

    @Override
    public void uncaughtException(Thread thread, Throwable ex) {
        ex.printStackTrace();
        if(!BuildConfig.DEBUG){
            System.exit(0);
        }
    }

    public Member getMember(){
        String memberString = SharePerferenceUtils.getIns(instance).getOAuth();
        if(TextUtils.isEmpty(memberString)){
            return null;
        }
        Gson gson = new Gson();
        try {
            Member member = gson.fromJson(memberString , Member.class);
            return member;
        }catch (Exception e){
            return null;
        }
    }
}
